export{}
//描述对象的形状，属性方法一一对应
interface Speakable{
	name:string;
	speak():void
}
let speakMan:Speakable = {
	name:'jack',
	speak(){}
}

// 行为的抽象
// 同名的接口可以写多个，类型会自动合并
interface Speakable{
	speak():void
}
interface Eatble{
	eat(): void
}
class Person implements Speakable,Eatble{
	name!: string;
	speak(): void {
		throw new Error("Method not implemented.");
	}
	eat(): void {
		throw new Error("Method not implemented.");
	}

}

//任意属性 
interface Person1{
	readonly id:number
	name:string
	[key:string]:any //包含任意属性
}
let p1:Person1 = {
	id:1,
	name:'jinyq',
	age:10
}

// 接口继承
interface Speakable2{
	speak():void
}
interface SpeakChinese extends Speakable2{
	speakChinese():void
}
class ChineseMan implements SpeakChinese{
	speakChinese(): void {
		console.log('speakChinese')
	}
	name!:string
	speak(){
		console.log('speak')
	}
}
let c1 = new ChineseMan();
c1.speak()

interface Person3 {
	readonly id:number
}
let p3:Person3={
	id:1
}
// p3.id =2

// 函数类型接口
interface Discount {
	(price:number):number
}
const discount :Discount =(price:number):number =>{
	return price *.8;
}

//可索引接口
interface User{
	[index:number] :string
}
let user:User ={
	0:'0',1:'1',2:'2'
}
let arr:User = ['1','2','3']

// 如何用接口约束类
interface Speakable{
	speak():void
}

// 构造函数类型
class Animal{
	constructor(public name:string){

	}
}
interface WithNameClass{
	new(name:string):Animal
}
function createAnimal (clazz:WithNameClass,name:string){
	return new clazz(name)
}
let a = createAnimal(Animal, 'jinyq');
console.log(a.name)